/*
   Copyright (C) 2022 Ivan Polyakov

   This file is part of fltube.

   fltube is free software: you can redistribute it and/or modify
   it under the terms of the GNU General Public License as published by
   the Free Software Foundation, either version 3 of the License, or
   (at your option) any later version.

   fltube is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   GNU General Public License for more details.
   
   You should have received a copy of the GNU General Public License
   along with this program.  If not, see <https://www.gnu.org/licenses/>.
 */

#include "SearchBox.hxx"

using namespace fltube;

SearchBox::SearchBox(int x, int y, int w, int h)
  : Fl_Group(x, y, w, h)
{
  begin();
  {
    input = new Fl_Input(x, y, w - search_btn_w + 1, h);
    input->box(FL_BORDER_BOX);

    Fl_Button *btn = new Fl_Button(
                     x + w - search_btn_w, y,
                     search_btn_w, h, "@search");
    btn->box(FL_BORDER_BOX);
    btn->callback(SearchButtonPressed, this);
  }
  end();

  resizable(input);
}

void SearchBox::SearchButtonPressed(Fl_Widget *wdt, void *val)
{
    SearchBox *sbox = static_cast<SearchBox*>(val);
    sbox->do_callback();
}
